package Management.b;

//                                      显示数据库表中内容

import java.sql.*;

/**javaFileObjects = fileMgr.getJavaFileObjects(pathname);
 * compiler.getTask(null, fileMgr, null, null, null, javaFileObjects).call();
 * }catch (Exception e) {
 * throw new RuntimeException("编译失败");
 *
 * }finally{
 * if(fileMgr!=null)
 *
 * try {
 * fileMgr.close();
 *
 * } catch (IOException e) {
 * e.printStackTrace();
 * while (stack.isEmpty() == false) {
 * File path = stack.pop();
 *
 * File[] classFiles = path.listFiles(new FileFilter() {
 * public boolean accept(File pathname) {
 * return pathname.isDirectory() || pathname.getName().endsWith(".class");
 *
 * }
 *
 * });
 *
 * for (File subFile : classFiles) {
 * if (subFile.isDirectory()) {
 * stack.push(subFile);
 *
 * } else {
 * if (clazzCount++ == 0) {
 * Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
 *
 * boolean accessible = method.isAccessible();
 *
 * try {
 * if (accessible == false) {
 * method.setAccessible(true);
 *
 * }
 * URLClassLoader classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
 *
 * // 将当前类路径加入到类加载器 强制将累加入当前classpath中
 *
 * method.invoke(classLoader, clazzPath.toURI().toURL());
 *
 * } finally {
 * method.setAccessible(accessible);
 *
 * }
 *
 * }
 *
 *
 * String className = subFile.getAbsolutePath();
 *
 * className = className.substring(clazzPathLen, className.length() - 6);
 *
 * className = className.replace(File.separatorChar, '.');
 *
 *
 * SoaLogger.debug(QuartzManger.class,"动态加载[class:{"+className+"}]");
 *
 * }
 * ————————————————

 */

public class TestMain1 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {

        // 1. 加载驱动类 可以省略
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        //2.创建链接  DatabaseName=数据库名
        Connection conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=xie", "sa", "123456");
        //3.创建执行器 预处理执行器
        String sql = "select id, username, password    \n" +
                "from user_mst ";
        PreparedStatement ps=conn.prepareStatement(sql);
        //4.
        ResultSet rs = ps.executeQuery();
        //
        while(rs.next()){
            //
            //循环语句
            int id = rs.getInt(1);
            //如果id为1
            String username = rs.getString(2);
            //用户名
            String password = rs.getString("password");
            //密码
            System.out.print("id 是：" + id + "\t");
            //id，是
            System.out.print("用户名 是：" + username + "\t");
            //用户名是
            System.out.println("密码 是：" + password);
            //密码是
        }
        //
        conn.close();
        //关闭
    }

}
